<?php 
include("db/connect.php");
if(@$_POST["type"]==1){
	$sqldeletecustomer="delete from customer where cus_id='".@$_POST["temp"]."'";
	$querydelete=mysql_query($sqldeletecustomer);
	}
	else{
		$sqlupdate="update customer set cus_name='".@$_POST["cus_name"]."',cus_lastname='".@$_POST["cus_lastname"]."',cus_addr='".@$_POST["cus_addr"]."',province_id='".@$_POST["province_id"]."',amphur_id='".@$_POST["amphur_id"]."',tambol_id='".@$_POST["tambol_id"]."',cus_postal='".@$_POST["cus_postal"]."',cus_tel='".@$_POST["cus_tel"]."',cus_mail='".@$_POST["cus_mail"]."' where cus_id='".@$_POST["temp"]."'";
		$queryupdatecustomer=mysql_query($sqlupdate);
		}
		$sqlselectcustomer="select * from customer,province,amphur,tambol";
		$sqlselectcustomer.=" where customer.province_id=province.province_id and";
		$sqlselectcustomer.=" customer.amphur_id=amphur.amphur_id and";
		$sqlselectcustomer.=" customer.tambol_id=tambol.tambol_id";
		$sqlselectcustomer.=" group by cus_id";
		$queryselectcustomer=mysql_query($sqlselectcustomer);
?>
<table width="100%" height="132" border="1">
  <tr>
    <td width="9%">ชื่อ</td>
    <td width="8%">นามสกุล</td>
    <td width="6%">ที่อยู่</td>
    <td width="6%">ตำบล</td>
    <td width="7%">อำเภอ</td>
    <td width="7%">จังหวัด</td>
    <td width="13%">รหัสไปรษณีย์</td>
    <td width="13%">เบอร์โทรศัพท์</td>
    <td width="6%">Email</td>
    <td width="6%">แก้ไข</td>
    <td width="6%">ลบ</td>
  </tr>
  <?php 
  while($resultcustomer=@mysql_fetch_array($queryselectcustomer)){
  ?>
  <tr>
    <td><?php echo $resultcustomer["cus_name"]?></td>
    <td><?php echo $resultcustomer["cus_lastname"]?></td>
    <td><?php echo $resultcustomer["cus_addr"]?></td>
    <td><?php echo $resultcustomer["tambol_name"]?></td>
    <td><?php echo $resultcustomer["amphur_name"]?></td>
    <td><?php echo $resultcustomer["province_name"]?></td>
    <td><?php echo $resultcustomer["cus_postal"]?></td>
    <td><?php echo $resultcustomer["cus_tel"]?></td>
    <td><?php echo $resultcustomer["cus_mail"]?></td>
   <td><a href="Javascript:ajaxmanage(2,<?php echo $resultcustomer["cus_id"];?>);">แก้ไข</a></td>
    <td><a href="Javascript:ajaxmanage(1,<?php echo $resultcustomer["cus_id"];?>);">ลบ</a></td>
  </tr>
  <?php }?>
</table>